<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<h2 style="text-align: center;">${book.title}</h2>
<hr/>
<ul>
    <li>
        <b><spring:message code="portal.webapp.label.category"/></b> ${book.category.name}
        <%--<a href="/category/${book.category.id}">${book.category.name}</a>--%>
    </li>
    <li><b><spring:message code="portal.webapp.label.authors"/>:</b></li>
    <ol>
        <c:forEach items="${book.authors}" var="author">
            <li>
                <a href="/author/${author.id}">${author.fullName}</a>
            </li>
        </c:forEach>
    </ol>
    <li>
        <b><spring:message code="portal.webapp.label.description"/></b> ${book.description}
    </li>
    <c:if test="${book.comments.size() > 0}">
        <li>
            <b><spring:message code="portal.webapp.label.comments"/>:</b>
        </li>
        <br/>
        <table class="contentTable">
            <tr>
                <td class="headerCell"><spring:message code="portal.webapp.label.title"/></td>
                <td class="headerCell"><spring:message code="portal.webapp.label.content"/></td>
                <td class="headerCell"><spring:message code="portal.webapp.label.reader"/></td>
                <td class="headerCell"><spring:message code="portal.webapp.label.dateAdded"/></td>
            </tr>
            <c:forEach var="c" items="${book.comments}">
                <tr>
                    <td>${c.title}</td>
                    <td>${c.content}</td>
                    <td><a href="/reader/${c.reader.id}">${c.reader.username}</a></td>
                    <td style="text-align: center;">${c.createdDate}</td>
                </tr>
            </c:forEach>
        </table>
    </c:if>
</ul>
<hr/>
<c:if test="${empty pageContext.request.remoteUser}">
    <div style="text-align: center; font-weight: bold;">
        <spring:message code="portal.webapp.label.loginRequest"/>
    </div>
</c:if>
<c:if test="${!empty pageContext.request.remoteUser}">
    Dodaj swój komentarz
    <form:form modelAttribute="comment">
        <form:hidden path="id"/>
        <form:hidden path="createdDate"/>
        <form:hidden path="lastUpdateDate"/>
        <%--<form:hidden path="book" />--%>
        <%--<form:hidden path="reader" />--%>
        <input type="hidden" name="reader" value="${pageContext.request.remoteUser}">
        <input type="hidden" name="book" value="${book.id}">

        <table>
            <tr>
                <td><spring:message code="portal.webapp.label.title"/></td>
                <td><form:input path="title"/> <form:errors path="title"/></td>
            </tr>
            <tr>
                <td><spring:message code="portal.webapp.label.content"/></td>
                <td><form:textarea path="content"/> <form:errors path="content"/></td>
            </tr>
            <%--<tr>--%>
            <tr>
                <td><input type="reset"/></td>
                <td><input type="submit"/></td>
            </tr>
        </table>
    </form:form>
</c:if>